package com.ojtest.demo;

public class code2 {
    public static void main(String[] args) {

    }
    public static int maxProduct(int[] nums) {
        int n = nums.length;
        int[] max = new int[n];
        int[] min = new int[n];
        max[0] = min[0] = nums[0];

        int ret = nums[0];
        for(int i = 1;i<n;i++){
            if(nums[i]>0){
                max[i] = Math.max(nums[i],max[i-1]*nums[i]);
                min[i] = Math.min(nums[i],min[i-1]*nums[i]);
            }else if(nums[i]<=0){
                max[i] = Math.max(nums[i],min[i-1]*nums[i]);
                min[i] = Math.min(nums[i],max[i-1]*nums[i]);
            }
            ret = Math.max(ret,max[i]);
        }
        return ret;
    }
}
